import type {
  OrderDetailResType,
  OrderListResType,
  OrderLogisticsRes,
  OrderParams,
  OrderPreResult,
  PostOrderParamsType
} from '@/types/order'
import { http } from '@/utils/request'

/**
 * 填写订单-获取预付订单
 */
export const getMemberOrderPreAPI = () => {
  return http<OrderPreResult>({
    url: '/member/order/pre',
    method: 'GET'
  })
}

/**
 * 填写订单-获取立即购买订单
 */
export const getMemberOrderPreNowAPI = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return http<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data
  })
}

/**
 * 提交订单
 * @param data 请求参数
 */
export const postMemberOrderAPI = (data: PostOrderParamsType) => {
  return http<{ id: string }>({
    url: '/member/order',
    method: 'POST',
    data
  })
}

/**
 * 获取订单详情
 * @param id 订单id
 */
export const getMemberOrderDetailAPI = (id: string) => {
  return http<OrderDetailResType>({
    url: `/member/order/${id}`,
    method: 'GET'
  })
}

// 模拟微信支付的接口
export const PayMockAPI = (data: { orderId: string }) => {
  return http({
    url: '/pay/mock',
    method: 'GET',
    data
  })
}

// 获取微信支付参数
// GET
// /pay/wxPay/miniPay

export const PayWxPayMiniPayAPI = (data: { orderId: string }) => {
  return http<WechatMiniprogram.RequestCommonPaymentOption>({
    url: '/pay/wxPay/miniPay',
    method: 'GET',
    data
  })
}

// /member/order/consignment/{id}
export const MockMemberOrderConsignmentAPI = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET'
  })
}

/**
 * 确认收货
 * @param id 订单id
 */
export const confirmMemberOrderAPI = (id: string) => {
  return http<OrderDetailResType>({
    url: `/member/order/${id}/receipt`,
    method: 'PUT'
  })
}

/**
 * 获取订单物流
 * @param id 订单编号
 */
export const getMemeberOrderLogisticsAPI = (id: string) => {
  return http<OrderLogisticsRes>({
    url: `/member/order/${id}/logistics`,
    method: 'GET'
  })
}

/**
 * 删除订单
 * @param data
 */
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
  return http({
    url: '/member/order',
    method: 'DELETE',
    data
  })
}

export const getMemberOrderListAPI = (data: OrderParams) => {
  return http<OrderListResType>({
    url: '/member/order',
    method: 'GET',
    data
  })
}
